﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MikroTransfer
{
    public partial class frmUrunEslestirme : Form
    {
        public frmUrunEslestirme()
        {
            InitializeComponent();
        }

        private void frmUrunEslestirme_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Turkcell Kod", typeof(string));
            dt.Columns.Add("Mikro Kod", typeof(string));

            if (File.Exists(Application.StartupPath + "\\kontor_urun_eslestirme.txt"))
            {
                using (StreamReader sr = new StreamReader(Application.StartupPath + "\\kontor_urun_eslestirme.txt"))
                {
                    string[] alanlar = null;
                    while (sr.Peek() > -1)
                    {
                        alanlar = sr.ReadLine().Split(';');
                        dt.Rows.Add(alanlar[0], alanlar[1]);
                    }
                    sr.Close();
                }
            }

            if (dt.Rows.Count == 0)
            {
                dt.Rows.Add("5 TL", "");
                dt.Rows.Add("10 TL", "");
                dt.Rows.Add("15 TL", "");
                dt.Rows.Add("20 TL", "");
                dt.Rows.Add("AVANTAJ (30 TL)", "");
                dt.Rows.Add("SÜPER (50 TL)", "");
                dt.Rows.Add("SÜPER PLUS (95 TL)", "");
                dt.Rows.Add("MEGA (180 TL)", "");
            }

            for (int i = 0; i < 20; i++)
            {
                dt.Rows.Add("", "");
            }

            gridControl1.DataSource = dt;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            using (StreamWriter sw = new StreamWriter(Application.StartupPath + "\\kontor_urun_eslestirme.txt", false))
            {
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    if (!string.IsNullOrEmpty(gridView1.GetRowCellValue(i, gridView1.Columns[0]).ToString()) && !string.IsNullOrEmpty(gridView1.GetRowCellValue(i, gridView1.Columns[1]).ToString()))
                    {
                        sw.WriteLine(string.Format("{0};{1}", gridView1.GetRowCellValue(i, gridView1.Columns[0]).ToString(), gridView1.GetRowCellValue(i, gridView1.Columns[1]).ToString()));
                    }
                }
                sw.Close();
            }
            this.Close();
        }
    }
}
